#!/bin/sh

# Updates the debian changelogs when you are on the top of a packaging branch,
# i.e. packaging/debian/jaunty/trunk/
#
# Only argument is the new version desired, plus packages you want to change
# or nothing if you want to change all

version=$1
shift
packs=$@

dist="focal"

if [ -z "$version" ]
then
    echo "Usage: update-changelogs <version>"
    exit 1
fi

if [ -z "$packs" ]
then
    packs=$(echo *)
fi

for dir in $packs
do
    if [ ! -f $dir/debian/changelog ]
    then
        continue
    fi

    module="zentyal-$dir"

    cat > $dir/debian/changelog.new <<EOF
$module ($version) $dist; urgency=low

  * New upstream release

 -- $DEBFULLNAME <$DEBEMAIL>  $(date -R)

EOF

cat $dir/debian/changelog >> $dir/debian/changelog.new
mv $dir/debian/changelog.new $dir/debian/changelog
done
